package com.cyt.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.cyt.entity.GongShi;
import com.cyt.entity.SheJiShi;
import com.cyt.util.DBManager;
//实现类
//公司信息
public class GongShiDaoImpl {//实体类名+DaoImpl
	  // 方法的语法结构
		//访问修饰符  返回值类型 方法名(参数列表){方法体}
		//目的 : 查询所有用户信息
	    public GongShi getGongShi(){
	    	
			Statement st=null;
			ResultSet rs=null;
			GongShi  gongShi=null;
	    	//1.建立连接
			Connection conn=DBManager.getConnection();
			//2.创建Statement执行对象(用来执行sql语句)
			try {//try 正常执行
				st= conn.createStatement();
				// 3.sql语句
				String sql="SELECT * FROM gongshi";
				//4.执行sql语句,返回结果集
				rs=st.executeQuery(sql);
				//5. 遍历结果集
				while(rs.next()) {
					String logo =rs.getString("logo");
					String name =rs.getString("name");
					String wangzhi =rs.getString("wangzhi");
					String jieshao =rs.getString("jieshao");
					String dianhua =rs.getString("dianhua");
					String youxiang =rs.getString("youxiang");
					String dizhi =rs.getString("dizhi");
					String xiangxi =rs.getString("xiangxi");
					String wenhua =rs.getString("wenhua");
					gongShi=new GongShi(logo, name, wangzhi, jieshao, dianhua, youxiang, dizhi, xiangxi, wenhua);
					
				}
				return gongShi;//正常情况返回集合
				
			} catch (SQLException e) {//catch 异常执行
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;//异常返回空
			}finally {
				DBManager.closeAll(conn, st, rs);
			}
			
	    }
	    
	    public int xiuGaiGongShi(GongShi gs ) {
			String sql="UPDATE gongshi set logo='"+gs.getLogo()+"',name='"+gs.getName()+"',wangzhi='"+gs.getWangzhi()+"',jieshao='"+gs.getJieshao()+"',dianhua='"+gs.getDianhua()+"',youxiang='"+gs.getYouxiang()+"',dizhi='"+gs.getDizhi()+"',xiangxi='"+gs.getXiangxi()+"',wenhua='"+gs.getWenhua()+"'"; 
					
			System.out.println(sql);
			return DBManager.executeUpdate(sql);
		}
	    
}
